package com.oocl.euc.core.maintenance.controller;

import com.oocl.euc.core.maintenance.model.Users;
import com.oocl.euc.core.maintenance.service.UsersService;
import com.oocl.euc.framework.base.controller.RESTController;
import com.oocl.euc.framework.base.service.BaseService;
import com.oocl.euc.framework.common.utils.ResponseEntityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping(value = "/rest/users")
public class UsersController extends RESTController<Users, String> {

    @Autowired
    UsersService usersService;

    @Override
    protected BaseService<Users, String> getBaseService() {
        return usersService;
    }

    @ResponseBody
    @RequestMapping(value = "/saveTempUser", method = RequestMethod.POST)
    public ResponseEntity<Users> saveTempUser(@RequestBody Users tempUser) {
        Users user = usersService.insertTempUser(tempUser);
        return ResponseEntityUtil.successInRestful(user);
    }

    @ResponseBody
    @RequestMapping(value = "/getTempUser")
    public ResponseEntity<List<Users>> getTempUsers() {
        List<Users> userList = usersService.getTempUsers();
        return ResponseEntityUtil.successInRestful(userList);
    }

    @ResponseBody
    @RequestMapping(value = "/getDepartments")
    public ResponseEntity<List<String>> getUserDepartments() {
        List<String> departments = usersService.getUserDepartments();
        return ResponseEntityUtil.successInRestful(departments);
    }
}
